﻿using System;
using System.Collections.Generic;

using D3Sparrow.Core.Common;
using D3Sparrow.Core.Structures;
using D3Sparrow.Common.Utilities.TextProcessing;

namespace D3Sparrow.Core.Wrap
{
    public class D3Actor
    {
        public uint m_dwBaseRact { get; private set; }		//RActor base address
        public uint m_dwBaseACD { get; private set; }		//ACD base address
        public bool m_bLinked { get; private set; }			//Indicates that actor has both structs (ACD and RActor) after linking
        public Vec3 m_pos { get; private set; }				//Actor world position
        public float m_dist { get; private set; }				//Distance from player
        public string m_Name { get; private set; }				//Actor proxy name
        public uint m_dwGUID { get; private set; }			//Actor GUID
        public ActorType m_Type { get; private set; }				//Actor type
        public MonsterRace m_MobRace { get; private set; }			//Monster race
        public MonsterType m_MobType { get; private set; }			//Monster type
        public uint SnoID { get; private set; }

        RActor ActorR;				//RActor data
        ActorCommonData ACD;				//ACD data
        SNOActor ActorSNO;			//SNO data

        unsafe public D3Actor(uint actorBase, Vec3 playerpos, bool bACD)
        {
            if (bACD)
            {
                Globals.MR.UnsafeReadToStruct<ActorCommonData>(actorBase);

                m_dwBaseACD = actorBase;
                m_dwGUID = ACD.id_acd;
                SnoID = ACD.id_sno;
                m_Name = ACD.name;
                m_pos = ACD.PosWorld;
            }
            else
            {
                Globals.MR.UnsafeReadToStruct<RActor>(actorBase);

                m_dwBaseRact = actorBase;
                m_dwGUID = ActorR.id_acd;
                SnoID = ActorR.id_sno;

                fixed (char* pc = ActorR.Name)
                {
                    m_Name = new string(pc);
                }

                m_pos = ActorR.Pos;
            }
        }
    }
}
